package fenzhixianjie.tanglian.exer03;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;


public class Main {

    private static int minStep = Integer.MAX_VALUE;
    public static void main(String[] args){
        Scanner read = new Scanner(System.in);
        int m = read.nextInt(), n = read.nextInt();
        int startRow = -1, startCol = -1;
        int endRow = -1, endCol = -1;
        int initBlood = read.nextInt();
        char[][] mat = new char[m][n];
        for (int i = 0; i < m; i++) {
            String line = read.next();
            for (int j = 0; j < n; j++) {
                char value = line.charAt(j);
                mat[i][j] = value;
                if (value == '!') {
                    startRow = i;
                    startCol = j;
                }
                if (value == '+') {
                    endRow = i;
                    endCol = j;
                }
            }
        }
        boolean[][] flag = new boolean[m][n];
        int[][] nextPos = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
        dfs(startRow, startCol, m, n, mat, endRow, endCol, flag, nextPos, 0, initBlood, initBlood);
        System.out.println(minStep == Integer.MAX_VALUE ? -1 : minStep);
    }

    private static void dfs(int curRow, int curCol, int rows, int cols, char[][] mat, int endRow, int endCol, boolean[][] flag, int[][] nextPos, int curStep, int curBlood, int initBlood) {
        flag[curRow][curCol] = true;
        if (curRow == endRow && curCol == endCol) {
            minStep = Math.min(minStep, curStep);
            flag[curRow][curCol] = false;
            return;
        }
        for (int i = 0; i < 4; i++) {
            int nextRow = curRow + nextPos[i][0];
            int nextCol = curCol + nextPos[i][1];
            if (nextRow >= 0 && nextRow < rows && nextCol >= 0 && nextCol < cols && !flag[nextRow][nextCol]) {
                if (mat[nextRow][nextCol] == '*') {
                    dfs(nextRow, nextCol, rows, cols, mat, endRow, endCol, flag, nextPos, curStep + 1, curBlood, initBlood);
                }
                if (mat[nextRow][nextCol] == 'w' && curBlood > 1) {
                    dfs(nextRow, nextCol, rows, cols, mat, endRow, endCol, flag, nextPos, curStep + 1, curBlood - 1, initBlood);
                }
                if (mat[nextRow][nextCol] == 'e') {
                    dfs(nextRow, nextCol, rows, cols, mat, endRow, endCol, flag, nextPos, curStep + 1, initBlood, initBlood);
                }
                if (mat[nextRow][nextCol] == '+') {
                    dfs(nextRow, nextCol, rows, cols, mat, endRow, endCol, flag, nextPos, curStep + 1, curBlood, initBlood);
                }
            }
        }
        flag[curRow][curCol] = false;
    }
}

